﻿using System;
using System.Collections.Generic;
using Sharp.DataTransferObject.CMS;
using Sharp.Domain.CMSBoundedContext.VIUModule.Aggregates;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Crosscutting;
using Sharp.Infrastructure.Search;

namespace Sharp.Application.CMS
{
    public partial class CMSServiceImpl
    {
        #region Column

        public Result DeleteColumns(Guid[] ids)
        {
            var res = new Result();
            if (ids == null)
            {
                res.Err = "参数不可为空。";
                return res;
            }

            _columnRepository.Remove(ids);

            Context.Commit();

            return res;
        }
        [Logging("保存栏目“{@p0.Name}”")]
        public Result SaveColumn(ColumnDTO dtoModel)
        {
            Result res = new Result();

            if (dtoModel.Id.IsEmpty())
            {
                _columnRepository.Add(dtoModel.To<Column>());
            }
            else
            {
                var persisted = _columnRepository.Get(dtoModel.Id);
                persisted.Name = dtoModel.Name;
                persisted.Remark = dtoModel.Remark;

                _columnRepository.Update(persisted);
            }
            _columnRepository.Context.Commit();
            return res;
        }

        public Result<ColumnDTO> GetColumnInfo(Guid id)
        {
            var res = new Result<ColumnDTO>();
            res.Data = _columnRepository.Get(id).To<ColumnDTO>();
            return res;
        }

        public PagedResult<ColumnDTO> GetColumnPaged(PagingFeature pf)
        {
            var paged = _columnRepository.Pagging(pf);

            return paged.To<Column, ColumnDTO>();
        }
        public Result<IList<ColumnDTO>> GetColumns()
        {
            var res = new Result<IList<ColumnDTO>>();
            res.Data = _columnRepository.GetList().To<List<ColumnDTO>>();
            return res;
        }
        #endregion
    }
}
